/*
 * 创建组件的packagejson文件
 * */
import { FsFile } from "./utils/FsFile.js";
import { createPackageJson } from "./templates";
import { log } from "./utils/utils.js";
import { resolve } from "path";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = resolve(dirname(__filename), "../lib/components");

// 文件根目录
// 创建文件对象
const fsFile = new FsFile(__dirname);

// 需要创建的文件列表
const files = {
  json: createPackageJson,
};

export async function createPackageJsonFile() {
  const folderNames = await fsFile.getFolderNames();
  if (!folderNames) return;
  folderNames.forEach(folder => {
    const filePath = fsFile.join(folder, "package.json");
    const fileContent = files.json(folder);
    // 创建文件并写入内容
    fsFile.createFile(filePath, fileContent);
  });
  log.success(`成功生成所有组件的package.json`);
}
